﻿#include "show_qlabel.h"

ShowQLabel::ShowQLabel(QWidget *parent) : QOpenGLWidget(parent)
{
    ;
}
void ShowQLabel::loadtextimage(QImage image,QString string_show,QColor color)
{
   m_image_show = image.copy();
   m_string_show=string_show;
   m_color=color;
   update();
}
void ShowQLabel::paintEvent(QPaintEvent *e)
{
    QPainter painter;
    painter.begin(this);
    if(!m_image_show.isNull())
        painter.drawImage(QPoint(0, 0), m_image_show);

    QPen pen(m_color, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
    painter.setPen(pen);
    QTextOption toption(Qt::AlignLeft | Qt::AlignTop);//Qt::AlignLeft | Qt::AlignVCenter | Qt::TextWrapAnywhere,
    toption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);

    if(!m_string_show.isNull())
    {
        painter.setFont(QFont("SimSun", 10));
        painter.setPen(pen);
        painter.drawText(m_image_show.rect(), m_string_show,toption);
    }
    painter.end();
}
